<!--添加气象参数-->
<template>
	<view>
		<!-- <Head :title="formData.status == '待核实' ? '事件核实反馈' : '事件处置反馈'"></Head> -->
		<view class="check-content">
			<uni-forms ref="form" size="mini" :model="formData" :rules="rules">
				<uni-forms-item label="温度" :label-width="70" name="weather">
					<view style="width: 100%!important;display: flex;flex-direction: row;">
						<view style="width: 85%!important;">
							<input v-model="formData.weather" :maxlength="100"
								style="border:1px solid #ededed;height: 32px;border-radius: 4px;padding-left: 10px;"
								placeholder="请输入" />
						</view>
						<view style="width: 10%!important;;margin-left: 10rpx;line-height: 2;">℃</view>
					</view>
				</uni-forms-item>
				<uni-forms-item label="湿度" :label-width="70" name="humidity">
					<view style="width: 100%!important;display: flex;flex-direction: row;">
						<view style="width: 85%!important;">
							<input v-model="formData.humidity" :maxlength="100"
								style="border:1px solid #ededed;height: 32px;border-radius: 4px;padding-left: 10px;"
								placeholder="请输入" />
						</view>
						<view style="width: 10%!important;;margin-left: 10rpx;line-height: 2;">%RH</view>
					</view>
				</uni-forms-item>
				<uni-forms-item label="气压" :label-width="70" name="pressure">
					<view style="width: 100%!important;display: flex;flex-direction: row;">
						<view style="width: 85%!important;">
							<input v-model="formData.pressure" :maxlength="100"
								style="border:1px solid #ededed;height: 32px;border-radius: 4px;padding-left: 10px;"
								placeholder="请输入" />
						</view>
						<view style="width: 10%!important;;margin-left: 10rpx;line-height: 2;">
							hPa
						</view>
					</view>

				</uni-forms-item>
				<uni-forms-item label="风向" :label-width="70" name="windDirection">
					<view style="width: 100%!important;">
						<input v-model="formData.windDirection" :maxlength="100"
							style="border:1px solid #ededed;height: 32px;border-radius: 4px;padding-left: 10px;"
							placeholder="请输入" />
					</view>
				</uni-forms-item>
				<uni-forms-item label="风速" :label-width="70" name="windSpeed">
					<view style="width: 100%!important;display: flex;flex-direction: row;">
						<view style="width: 85%!important;">
							<input v-model="formData.windSpeed" :maxlength="100"
								style="border:1px solid #ededed;height: 32px;border-radius: 4px;padding-left: 10px;"
								placeholder="请输入" />
						</view>
						<view style="width: 10%!important;margin-left: 10rpx;line-height: 2;">m/s</view>
					</view>
				</uni-forms-item>
				<uni-forms-item label="备注" :label-width="70" name="remark">
					<view style="width: 100%!important;">
						<input v-model="formData.remark" :maxlength="100"
							style="border:1px solid #ededed;height: 32px;border-radius: 4px;padding-left: 10px;"
							placeholder="请输入" />
					</view>
				</uni-forms-item>
			</uni-forms>
		</view>
		<view class="check-button">
			<button type="primary" class="mini-btn" @tap="submit">保存</button>
		</view>

	</view>


</template>

<script setup>
	import {
		ref,
		computed
	} from 'vue'
	import {
		onLoad
	} from '@dcloudio/uni-app';
	// import Head from '@/components/head/head.vue'
	import SliderBar from './sliderBar.vue'
	import {
		getDictBiz,
		getSysDictBiz,
		submitPatrol,
		getPatrolDetail,
	} from "@/api/patrol.js"
	import {
		weatherRecord
	} from '@/api/deviceTest.js';
	const formData = ref({
		weather: "",
		humidity: "",
		pressure: "",
		windSpeed: "",
		windDirection: "",
        factoryId:uni.getStorageSync('factoryId')


	})
	const status = ref([]);
	const floors = ref([]);

	const points = ref([]);
	const pointsDic = ref([]);
	const areas = ref([]);
	const types = ref([]);
	const directionList = ref([]);
	const imageUrl = ref("");

	function dateFormat(date, format) {
		format = format || 'yyyy-MM-dd hh:mm:ss';
		if (date !== 'Invalid Date') {
			let o = {
				'M+': date.getMonth() + 1, //month
				'd+': date.getDate(), //day
				'H+': date.getHours(), //hour
				'm+': date.getMinutes(), //minute
				's+': date.getSeconds(), //second
				'q+': Math.floor((date.getMonth() + 3) / 3), //quarter
				S: date.getMilliseconds(), //millisecond
			};
			if (/(y+)/.test(format))
				format = format.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
			for (let k in o)
				if (new RegExp('(' + k + ')').test(format))
					format = format.replace(
						RegExp.$1,
						RegExp.$1.length === 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length)
					);
			return format;
		}
		return '';
	}


	//时间日期插件
	import lekeDatetimeStyler from '@/components/leke-datetime-styler/leke-datetime-styler.vue'

	const showDateStyler = ref(false)

	const model = ['year', 'month', 'day', 'hour', 'minute', 'second']

	// 确认选择回调
	const handShowDateConfirm = (e) => {
		showDateStyler.value = false
		formData.value.inspectDate = e
		console.log('回调时间===>', e)
	}

	// 取消选择回调
	const handShowDateCancel = () => {
		showDateStyler.value = false
		console.log('取消===>')
	}



	const pointAreaSelectChange = (e) => {
		formData.value.pointAreaName = e.value.text;
		formData.value.pointArea = e.value.value;


	}

	

	const pointTypeSelectChange = (e) => {
		formData.value.pointTypeName = e.value.text;
		formData.value.pointType = e.value.value;

	}

	const pointRealSelectChange = (e) => {
		formData.value.pointRealName = e.value.text;
		formData.value.pointName = e.value.value;
	}





	const pointFloorSelectChange = (e) => {
		// formData.value.pointRealName = e.value.text;
		formData.value.problemFloor = e.value.value;
	}


	const handleDictData = (list, key, dictKey) => {
		let arr = []
		list.map(v => {
			let item = {
				text: v.dictValue,
				value: v.dictKey
			};
			if (formData.value[key] == v.dictKey) {
				formData.value[dictKey] = item;
			}
			arr.push(item)
		})
		return arr;
	}


	const form = ref(null)

	const imgList = ref([])

	const deleteFileFn = (info) => {
		const idx = info.index == 0 ? 0 : info.index + 1;
		imgList.value.splice(idx);
		// formData.value.attachList.splice(idx);
		console.log('delete==')
	}

	// 提交
	const submit = () => {
		form.value.validate().then(res => {
			doSubmit();
		}).catch(err => {
			console.log('表单错误信息：', err);
		})

	}

	const doSubmit = () => {
		const factoryId = uni.getStorageSync('factoryId');
		let params = JSON.parse(JSON.stringify(formData.value));
		//console.log('params', params)
		weatherRecord(params).then(res => {
			//console.log("rrrrrr",res);
			if(res.code == 200){
			uni.showToast({
				icon: 'none',
				title: "提交成功！"
			})
			//将数据放入缓存
			let templist = [];
			templist.push(params);
			uni.setStorageSync('meteorologicalParameters',templist);
			setTimeout(function() {
				uni.navigateTo({
							   url: '/pages/testing/meteorologicalParametersList'
							}); //返回气象列表页
			}, 1000)
			}
		})
	}
	const select = (e) => {
		let that = this
		uni.showLoading({
			title: "图片上传中"
		});
		const tempFilePaths = e.tempFilePaths;
		for (var i in tempFilePaths) { //多文件
			uni.uploadFile({
				// url: '/app/blade-resource/oss/endpoint/put-file-attach', //上传接口
				url: '/app/blade-resource/oss/endpoint/put-file-without-login', //上传接口
				filePath: tempFilePaths[i],
				name: 'file',
				header: {
					Authorization: 'Basic c2FiZXI6c2FiZXJfc2VjcmV0',
					'Blade-Auth': 'bearer ' + uni.getStorageSync('token')
				},
				success: (uploadFileRes) => {
					uni.hideLoading();
					try {
						const back = JSON.parse(uploadFileRes.data);
						// if (uploadFileRes.statusCode == 200) {
						// 	that.infos.pathList.push(back.data);
						// } else {
						// 	uni.showToast(back.msg)
						// }
						// for (const item of back.data) {
						back.data['id'] = back.data.attachId
						imgList.value.push(back.data)
						console.log('上传成功', imgList)
						// formData.value.attachList.push(back.data);
					} catch (e) {}
					// }
				},
				fail: () => {
					uni.hideLoading();
					uni.showToast("图片上传失败，请联系开发！")
				},
				complete: function() {
					uni.hideLoading();
				}
			});
		}

	}

	// 获取上传进度
	const progress = (e) => {
		console.log('上传进度：', e)
	}

	// 上传成功
	const success = (e) => {
		console.log('上传成功')
	}

	// 上传失败
	const fail = (e) => {
		console.log('上传失败：', e)
	}
	//距离变化函数
	const change = () => {

	}
</script>

<style lang="scss" scoped>
	.select-item {
		width: 100rpx !important;
	}

	.content {
		display: flex;
		flex-wrap: wrap;
		max-width: 100%;
	}

	.check-content {
		// height: calc(100vh - 330rpx);
		overflow: auto;
		margin: 26rpx 31rpx 0;
		padding: 26rpx 26rpx 80rpx;
		background: #FFFFFF;
		box-shadow: 0px 3rpx 10rpx 0px rgba(0, 0, 0, 0.1);
		border-radius: 5rpx;
	}

	.check-button {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		padding: 25rpx 82rpx;
		background: white;
		z-index: 2;
		box-sizing: border-box;
		padding: 20rpx 30rpx;
		background: rgba(255, 255, 255, 0.6);

		uni-button {
			line-height: 80rpx !important;
			font-size: 26rpx;
		}
	}

	.item-inline {
		display: flex;
		margin-bottom: 22px;

		view:nth-child(1) {
			font-size: 14px;
			color: #606266;
			min-width: 80px;
		}

	}

	.pointer-name {
		//padding-left:20rpx;
		margin-bottom: 20rpx;
		//border-bottom: solid 1rpx  #606266 ;
		font-weight: bold;
		color: #606266;
	}

	uni-input {
		font-size: 12px !important;
	}

	uni-textarea {
		height: 100rpx;
		font-size: 12px !important;
	}
</style>
<style lang="scss">
	.check-content {
		.uni-data-checklist .checklist-group .checklist-box.is--tag.is-checked {
			background: linear-gradient(0deg, #455BDF 0%, #5970FA 100%);
			width: 21%;
			height: 80rpx;
			text-align: center;

			.checklist-text {
				color: #fff;
			}
		}

		.uni-data-checklist .checklist-group .checklist-box.is--tag {
			width: 21%;
			height: 80rpx;
			background: #FFFFFF;
			border: 1rpx solid #455BDF;
			border-radius: 10rpx;
		}

		.uni-data-checklist .checklist-group .checklist-box .checklist-content {
			justify-content: center;
		}

		.uni-data-checklist .checklist-group .checklist-box.is--tag .checklist-text {
			color: #455BDF;
			font-size: 28rpx;
			font-family: Source Han Sans CN;
			font-weight: 500;
		}

		.uni-forms-item__label {
			font-size: 32rpx;
			font-family: Source Han Sans CN;
			font-weight: 500;
			color: #1B1D20;
			padding: 0px !important;
		}

		.uni-textarea-textarea {
			font-size: 28rpx;
		}

		.uni-forms-item .is-required {
			margin-right: 10rpx;
		}
	}

	.item-inline {
		// flex-direction: row !important;
		align-items: center !important;

		.uni-forms-item__label {
			flex-basis: 200px !important;
			// min-width: 200px !important;
		}

		.uni-forms-item__content {
			padding-left: 20px;
		}
	}

	.img-list {
		margin: 1%;
		width: 30%;
		height: 28%;
		padding-top: 30%;
		border: 3rpx solid rgb(238, 238, 238);
	}
</style>